/*******************************************************************************
 * Copyright (c) 2006 CEA List.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     CEA List - initial API and implementation
 *******************************************************************************/
package com.cea.papyrus.diagram.composite.helper;

import org.eclipse.uml2.uml.CollaborationUse;
import org.eclipse.uml2.uml.Element;

import com.cea.papyrus.core.helper.NodeHelper;
import com.cea.papyrus.diagraminterchange2.di2.Diagram;
import com.cea.papyrus.diagraminterchange2.di2.GraphElement;
import com.cea.papyrus.diagraminterchange2.di2.Uml1SemanticModelBridge;

/**
 * 
 */
public class NodeCollaborationUseHelper extends NodeHelper{


	/**
	 * 
	 * 
	 * @param parent 
	 * 
	 * @return 
	 */
	public boolean canCreateGraphElement(GraphElement parent) {
		Element parentElt = null;
		if(parent instanceof Diagram) {
			// should check if parent semantic model element is a right parent
			parentElt= ((Uml1SemanticModelBridge)((Diagram)parent).getOwner()).getElement();
		} else if (parent.getSemanticModel()!=null){
			parentElt= ((Uml1SemanticModelBridge)parent.getSemanticModel()).getElement();
		}

		if(parentElt!=null){
			return canCreateUMLElement(parentElt);
		}

		return false;
	}


/*
 * (non-Javadoc)
 * @see com.cea.papyrus.common.factories.INodeFactory#createElement(java.lang.String, org.eclipse.uml2.uml.umlElement)
 */
/**
 * 
 * 
 * @param umlParent 
 * @param name 
 * 
 * @return 
 */
public org.eclipse.uml2.uml.Element createUMLElement(String name, org.eclipse.uml2.uml.Element umlParent){
	return ((org.eclipse.uml2.uml.Class)umlParent).createCollaborationUse(name);		
}


/* (non-Javadoc)
 * @see com.cea.papyrus.common.factories.INodeFactory#canExecuteCreateElement(org.eclipse.uml2.uml.Element)
 */
/**
 * 
 * 
 * @param umlParent 
 * 
 * @return 
 */
public boolean canCreateUMLElement(Element umlParent) {
	if(umlParent instanceof org.eclipse.uml2.uml.Class) {
		return true;
	}
	return false;
}

/* (non-Javadoc)
 * @see com.cea.papyrus.common.factories.INodeFactory#addElement(org.eclipse.uml2.uml.Element, org.eclipse.uml2.uml.Element)
 */
/**
 * 
 * 
 * @param element 
 * @param umlParent 
 * 
 * @return 
 */
public boolean addUMLElement(Element element, Element umlParent) {
	return ((org.eclipse.uml2.uml.Class)umlParent).getCollaborationUses().add((CollaborationUse)element);
}

/* (non-Javadoc)
 * @see com.cea.papyrus.common.factories.INodeFactory#removeElement(org.eclipse.uml2.uml.Element, org.eclipse.uml2.uml.Element)
 */
/**
 * 
 * 
 * @param element 
 * @param umlParent 
 * 
 * @return 
 */
public boolean removeUMLElement(Element element, Element umlParent) {
	return ((org.eclipse.uml2.uml.Class)umlParent).getCollaborationUses().remove(element);
}

/* (non-Javadoc)
 * @see com.cea.papyrus.common.factories.INodeFactory#getBaseString()
 */
/**
 * 
 * 
 * @return 
 */
public String getBaseString() {
	return "CollaborationUse_"; //$NON-NLS-1$
}
}
